/*
    Project:        Home Power Control
    File:           HPCButton.cpp
    Author:         christian@karunamusic.at
    Date:           12.2014
    Description:    Simple class to cover a button.
 */

#include <wiringPi.h>
#include "globals.h"
#include "HPCButton.h"

HPCButton::HPCButton( unsigned long id, unsigned int pin, unsigned int interval )
    : HPCThreadedSensor(id,pin,interval)
{
    PROFILE_THIS;
    m_Old = false;
}

HPCButton::~HPCButton()
{
    PROFILE_THIS;
}

void HPCButton::Measure()
{
    unsigned int v = digitalRead(m_Pin);
    m_Value = (v == 1);
}

bool HPCButton::hasChanged()
{
    PROFILE_THIS;

    Measure();
    LOG( debug, "Measured value: " << (bool)m_Value );

    return (m_Value != m_Old);
}
